package com.winderinfo.yikaotianxia.ui.home;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.winderinfo.yikaotianxia.R;

import java.util.List;

public class TouTiaoAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    private List<ToutiaosBean.ToutiaoBean> list;

    public TouTiaoAdapter(Context context, List<ToutiaosBean.ToutiaoBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_home_tou, viewGroup, false);
        SelectedViewHolder selectedViewHolder = new SelectedViewHolder(view);
        return selectedViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, final int i) {
        SelectedViewHolder selectedViewHolder = (SelectedViewHolder) viewHolder;
        //设置内容
        ToutiaosBean.ToutiaoBean.YkProfessionalBean ykProfessional = list.get(i).getYkProfessional();
        selectedViewHolder.tou_title.setText(ykProfessional.getName());
        selectedViewHolder.tou_text.setText(list.get(i).getTitle());
        //回调ID
        selectedViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onId != null) {
                    onId.getId(list.get(i).getId());
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class SelectedViewHolder extends RecyclerView.ViewHolder {

        private final TextView tou_title, tou_text;

        public SelectedViewHolder(@NonNull View itemView) {
            super(itemView);
            tou_title = itemView.findViewById(R.id.tou_title);
            tou_text = itemView.findViewById(R.id.tou_text);
        }
    }

    //接口回调
    public interface OnId {
        void getId(int id);
    }

    public OnId onId;

    public void setOnId(OnId onId) {
        this.onId = onId;
    }

}
